
package net.badcurrent.ldapodm.config;

import org.apache.commons.collections.map.MultiValueMap;

import java.util.Collection;
import java.util.List;
import java.util.ArrayList;

/**
 * <code>ClassMetaData</code> contains the mapping metadata for a Class.  It abstracts
 * the meta data from the underlying configuration mechanism (ie, Annotations, XML,
 * etc.)
 *
 * @author John D'Emic <john.demic@gmail.com>
 */
public class ClassMetaData {
    private MultiValueMap propertyToAttributeMap;
    private Class clazz;
    private String structuralObjectClass;
    private List<String> objectClasses;

    public ClassMetaData() {

    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

    public ClassMetaData(Class clazz) {
        this.clazz = clazz;
        propertyToAttributeMap = new MultiValueMap();
    }

    @SuppressWarnings({"unchecked"})
    public void addAttribute(String propertyName, String attributeName) {
        propertyToAttributeMap.put(propertyName, attributeName);
    }

    @SuppressWarnings({"unchecked"})
    public Collection<String> getAttributesForProperty(String propertyName) {
        return propertyToAttributeMap.getCollection(propertyName);
    }

    public Class getClazz() {
        return clazz;
    }

    @SuppressWarnings({"unchecked"})
    public Collection<String> getProperties() {
        return propertyToAttributeMap.keySet();
    }

    public String getStructuralObjectClass() {
        return structuralObjectClass;
    }

    public void setStructuralObjectClass(String structuralObjectClass) {
        this.structuralObjectClass = structuralObjectClass;
    }

    public List<String> getObjectClasses() {
        return objectClasses;
    }

    public void addObjectClass(String objectClass) {
        if (objectClasses == null)
            objectClasses = new ArrayList<String>();
        objectClasses.add(objectClass);
    }


}
